package com.yanqu.road.server.cmd.charitable;

import com.yanqu.road.logic.config.GameConfig;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.charitable.CharitableDoTenTimeResult;
import com.yanqu.road.server.gameplayer.module.charitable.CharitableModule;
import com.yanqu.road.server.gameplayer.module.player.PlayerModule;
import com.yanqu.road.server.pb.CharitablePb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Author wpj
 * @Date 2020/8/30
 */
@Cmd(code = GameProtocol.S_CHARITABLE_WORK_DO_TEN, desc = "10次行善")
public class CharitableWorkDoTenCmd extends AbstractCommand {
    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }


    CharitableDoTenTimeResult charitableDoTenTimeResult;

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (player.getModule(PlayerModule.class).getUserInfo().getTitleId() < GameConfig.ONE_KEY_CHARITABLE_TEN) {
            charitableDoTenTimeResult = new CharitableDoTenTimeResult(GameErrorCode.E_CHARITABLE_ONE_KEY_UNLOCK);
            return;
        }
        charitableDoTenTimeResult = player.getModule(CharitableModule.class).doCharitableTen(10);
    }

    @Override
    public void sendData(GamePlayer player) {
        player.sendPacket(ClientProtocol.U_CHARITABLE_WORK_DO_TEN, CharitablePb.getCharitableTenDoResp(charitableDoTenTimeResult));
    }
}
